package com.lsjr.callback;

import android.util.Log;

import com.google.gson.Gson;
import com.lsjr.bean.EncryptBean;
import com.lsjr.net.Encrypt;

public abstract class StringCallBack extends BaseCallBack<String> {

    @Override
    public void onNext(String response) {
        Log.e("StringCallBack", "网络请求成功" + response);
        response = response.replace("null", "\"\"");
        final String finalResponse = response;
        EncryptBean encryptBean = new Gson().fromJson(finalResponse, EncryptBean.class);
        final String dataString = Encrypt.transEncrytionDataStringRetrofit(encryptBean);
        mDelivery.post(new Runnable() {
            @Override
            public void run() {
                Log.e("StringCallBack", "解密数据" + dataString);
                onSuccess(dataString);
            }
        });
    }


    @Override
    public void onError(final Throwable e) {
        mDelivery.post(new Runnable() {
            @Override
            public void run() {
                onXError(e.getMessage());
            }
        });
    }


    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onCompleted() {
    }

    protected abstract void onXError(String exception);


    protected abstract void onSuccess(String response);


}